Import Libraries


In [1]:
import cv2

In [2]:
import matplotlib.pyplot as plt

Read image in grayscale


In [3]:
img_gray = cv2.imread('bike.jpg',cv2.IMREAD_GRAYSCALE)

In [4]:
plt.imshow(img_gray, cmap='gray')


Out[4]:
<matplotlib.image.AxesImage at 0x7f19c6109f98>

In [5]:
plt.show()



In [6]:
print('Gray image shape:', img_gray.shape)


Gray image shape: (590, 670)

In [7]:
print('File_size:', img_gray.size/1024/8, 'KB')


File_size: 48.25439453125 KB

Crop Image


In [8]:
img_cropped = img_gray[250:550,400:650]

In [9]:
plt.imshow(img_cropped, cmap='gray')


Out[9]:
<matplotlib.image.AxesImage at 0x7f19c487cdd8>

In [10]:
plt.show()



In [11]:
print('Cropped image shape:', img_cropped.shape)


Cropped image shape: (300, 250)

In [12]:
print('File_size_cropped:', img_cropped.size/1024/8, 'KB')


File_size_cropped: 9.1552734375 KB